﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            //var list = new List<MyImageData>();
            //list.Add(new MyImageData(@"E:\pic\11.jpg"));
            //list.Add(new MyImageData(@"E:\pic\112.jpg"));
            //list.Add(new MyImageData(@"E:\pic\113.jpg"));
            //list.Add(new MyImageData(@"E:\pic\114.jpg"));
            var item = new ListBoxItem();
            item.Content = "test";
            colorListbox.Items.Add(item);

           

        }

        public void SListView_ItemDoubleClick(object sender, MouseButtonEventArgs e)
        {
            
        }

        protected int eventCounter = 0;

        private void SomethingClicked(object sender, RoutedEventArgs e)
        {
            eventCounter++;
            string message = "#" + eventCounter.ToString() + ":\r\n" +
                "Sender:" + sender.ToString() + ":\r\n" +
                "Source:" + e.Source + ":\r\n" +
                "Original Source:" + e.OriginalSource;
            lstMessage.Items.Add(message);
            e.Handled = (bool)chkHandle.IsChecked;
        }

        
        private void DoSomething(object sender, RoutedEventArgs e)
        {
            var btn = (Button)e.Source;
            var tag = ((FrameworkElement)sender).Tag;
                
           
            lstMessage.Items.Add((string)tag);
        }
        private void cmdClear_Click(object sender, RoutedEventArgs e)
        {
            Binding bingding = new Binding();
            bingding.Source = sliderFontSize;
            bingding.Path = new PropertyPath("Value");
            bingding.Mode = BindingMode.TwoWay;
            MyTextBlock.SetBinding(TextBlock.FontSizeProperty, bingding);

            lstMessage.Items.Clear();
        }

        private void time_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectTime = time.SelectedDate;
            lstMessage.Items.Add(selectTime.ToString());
        }
    }

    public class MyImageData
    {
        public MyImageData(string filepath)
        {
            var curBitmap = (Bitmap)System.Drawing.Image.FromFile(filepath);
            Image1 = ConvertBitmap(curBitmap);
        }
        public MyImageData(Bitmap firstBit)
        {
            if (firstBit != null)
            {
                Image1 = ConvertBitmap(firstBit);
            }
        }

        public BitmapImage Image1 { get; set; }

        public BitmapImage Image2 { get; set; }

        private BitmapImage ConvertBitmap(System.Drawing.Bitmap bitmap)
        {
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            BitmapImage image = new BitmapImage();
            image.BeginInit();
            ms.Seek(0, SeekOrigin.Begin);
            image.StreamSource = ms;
            image.EndInit();

            return image;
        }
    }
}
